﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace 链表
{
    public class Node<T> : ICloneable where T : class
    {
        public Node()
        {
        }
        public Node(T t)
        {
            this.t = t;
        }

        /// <summary>
        /// 存储下一个节点
        /// </summary>
        public Node<T> nextNode { get; set; }
        /// <summary>
        /// 存储的数据
        /// </summary>
        public T t { get; set; }

        public object Clone()
        {
            object retval;
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                //序列化成流
                bf.Serialize(ms, this);
                ms.Seek(0, SeekOrigin.Begin);
                //反序列化成对象
                retval = bf.Deserialize(ms);
                ms.Close();
            }
            return (Node<T>)retval;
        }
    }
}
